<template>
  <div class="L-login-container">
    <div class="L-margin-30 L-text-align-center">
      <img src="@/assets/images/BIPlogo.png">
    </div>
    <van-cell-group inset>
      <van-field type="password" v-model="oldPassword" required label="旧密码" placeholder="请输入旧密码" />

      <van-field type="password" v-model="newPassword" required label="新密码" placeholder="请输入新密码" />
      <van-field type="password" v-model="confirmPassword" required label="确认密码" placeholder="请输入确认密码" />
    </van-cell-group>

    <div class="L-margin-top-40 L-text-align-center">
      <van-button @click="handleSubmit" type="primary" round size="large" class="L-login-btn">提交</van-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { showLoadingToast, showSuccessToast, showToast } from "vant";
import { changepwsave } from "@/request/api/login";
import { useRouter } from "vue-router";

const router = useRouter();

const oldPassword = ref("");
const newPassword = ref("");
const confirmPassword = ref("");

//修改密码
function handleSubmit() {
  const data = {
    oldpassword: oldPassword.value,
    newpassword: newPassword.value,
    confirmpassword: confirmPassword.value,
  };
  showLoadingToast({
    message: "发送中...",
    forbidClick: true,
    duration: 0,
  });

  changepwsave(data).then((res) => {
    if (res.code === 0) {
      showSuccessToast("修改密码成功");
      setTimeout(() => {
        router.go(-1);
      }, 2000);
    } else {
    }
  });
}
</script>

<style scoped>
</style>@/request/api/login